//
//  TipsView.m
//  CedarFinancialPlanner
//
//  Created by lshenrong on 2018/5/29.
//  Copyright © 2018年 cedarhd. All rights reserved.
//

#import "TipsView.h"
#include <UIView+TYAlertView.h>



@interface TipsView()

@property (nonatomic,copy) NSString *contentStr;


@end



@implementation TipsView

- (instancetype)initWithContent:(NSString *)content{
    if (self = [super init]) {
        self.backgroundColor=[UIColor whiteColor];
        AvoidNullString(content);
        self.contentStr = content;
        self.layer.cornerRadius = 12.0;
        self.layer.masksToBounds = YES;
        self.frame = CGRectMake(0, 0, 316, 160);
        [self setupSubviews];
    }
    return self;
}

- (void)dealloc{
    LogDealloc
}

- (void)setupSubviews{
    UILabel *titleLbl = [[UILabel alloc]init];
    MACRO_UILabel_ConfigureNoFontSize(titleLbl, @"提示", kBlackColor);
    titleLbl.font = PingFangZhongChangGui_MediumForFont(18);
    titleLbl.textAlignment = NSTextAlignmentCenter;
    [self addSubview:titleLbl];
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(1);
        make.right.equalTo(self).offset(-1);
        make.top.equalTo(self).offset(20);
    }];
    
    
    UILabel *detailsLbl = [[UILabel alloc]init];
    MACRO_UILabel_Configure(detailsLbl,  self.contentStr, kBlackColor, 13);
    detailsLbl.textAlignment = NSTextAlignmentCenter;
    
    [self addSubview:detailsLbl];
    [detailsLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(titleLbl.mas_bottom).offset(15);
    }];
    
    @weakify(self)
    CedarButton *confirmBtn =  [CedarButton buttonWithRegisterText:@"确定"];
    confirmBtn.clickEvent = ^{
        @strongify(self)
        [self hideView];
        if(self.confirmHandler){
            self.confirmHandler();
        }

    };
    [confirmBtn PFCGStyleFontSize:18.0];
    [self addSubview:confirmBtn];
    [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).mas_offset(-50);
        make.left.equalTo(self).mas_offset(50);
        make.bottom.equalTo(self).mas_offset(-20);
        make.height.mas_offset(kCedarButtonHeight);
    }];
}

- (void)hideAlertView{
    [self hideView];
}
@end
